﻿using KPI.Data;
using KPI.Entity;
using KPI.Entity.Entitys.Dto;
using KPI.Entity.Entitys.Https;
using KPI.Entity.Entitys.VO;
using System;
using System.Collections.Generic;
using TYBase;

namespace KPI.Api
{
    public class QuesionNaireApi
    {
        public static R<string> CreateQuestionNare(ExamRecordInfo dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(dto).SetBaseUri(KPIData.ServerURL).SetUrl($"/exam/").SetPost();
                if (!http.Excute(out var data))
                {
                    return R<string>.Fail("数据异常");
                }
                return data.AsModel<R<string>>();
            }
            catch (Exception ex)
            {
                return R<string>.Fail("数据异常");
            }
        }
        public static R<ExamRecordVO> GetQuestionNareInfo(string questionNaireId)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetGetData(new { id = questionNaireId }).SetBaseUri(KPIData.ServerURL).SetUrl($"/exam/all");
                if (!http.Excute(out var data))
                {
                    return R<ExamRecordVO>.Fail("数据异常");
                }
                return data.AsModel<R<ExamRecordVO>>();
            }
            catch (Exception ex)
            {
                return R<ExamRecordVO>.Fail("数据异常");
            }
        }


        public static R<ExamRecordVO> AddAnswerForUser(ExamUserInfoDto dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(dto);
                http.SetPost().SetBaseUri(KPIData.ServerURL).SetUrl($"/publish/answer");
                if (!http.Excute(out var data))
                {
                    return R<ExamRecordVO>.Fail("数据异常");
                }
                return data.AsModel<R<ExamRecordVO>>();
            }
            catch (Exception ex)
            {
                return R<ExamRecordVO>.Fail("数据异常");
            }
        }

        public static R<RP<ExamRecordVO>> GetQuestionNareList(ExamRecordQuery dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetGetData(dto).SetBaseUri(KPIData.ServerURL).SetUrl($"/exam");
                if (!http.Excute(out var data))
                {
                    return R<RP<ExamRecordVO>>.Fail("数据异常");
                }
                return data.AsModel<R<RP<ExamRecordVO>>>();
            }
            catch (Exception ex)
            {
                return R<RP<ExamRecordVO>>.Fail("数据异常");
            }
        }
        public static R<object> UpdateQuestionNareInfo(ExamRecordVO dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(dto)
                    .SetBaseUri(KPIData.ServerURL).SetUrl($"/exam").SetPut();
                if (!http.Excute(out var data))
                {
                    return R<object>.Fail("数据异常");
                }
                return data.AsModel<R<object>>();
            }
            catch (Exception ex)
            {
                return R<object>.Fail("数据异常");
            }
        }


        public static R<object> UpdateQuestionNaireBaseInfo(ExamRecordVO dto)
        {
            /// luna / assist / v1 / exam / base
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(dto).SetBaseUri(KPIData.ServerURL).SetUrl($"/exam/base").SetPut();
                if (!http.Excute(out var data))
                {
                    return R<object>.Fail("数据异常");
                }
                return data.AsModel<R<object>>();
            }
            catch (Exception ex)
            {
                return R<object>.Fail("数据异常");
            }
        }

        public static R<object> DeleteQuestionNaire(string id)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                http.SetData(new { deleteId = id })
                    .SetBaseUri(KPIData.ServerURL)
                    .SetUrl($"/exam").SetDelete();
                if (!http.Excute(out var data))
                {
                    return R<object>.Fail("数据异常");
                }
                return data.AsModel<R<object>>();
            }
            catch (Exception ex)
            {
                return R<object>.Fail("数据异常");
            }
        }

        public static R<object> PublishExam(PublishExamInfo dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(dto).SetBaseUri(KPIData.ServerURL).SetPut().SetUrl($"/exam/publish");
                if (!http.Excute(out var data))
                {
                    return R<object>.Fail("数据异常");
                }
                return data.AsModel<R<object>>();


            }
            catch (Exception ex)
            {
                return R<object>.Fail("数据异常");
            }
        }


        public static R<RP<UserExamInfoVO>> GetQuestionNaireByUserAndOffice(string userId, string officeCode)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetGetData(new { userId = userId, officeCode = officeCode }).SetBaseUri(KPIData.ServerURL).SetUrl($"/publish/office");
                if (!http.Excute(out var data))
                {
                    return R<RP<UserExamInfoVO>>.Fail("数据异常");
                }
                return data.AsModel<R<RP<UserExamInfoVO>>>();
            }
            catch (Exception ex)
            {
                return R<RP<UserExamInfoVO>>.Fail("数据异常");
            }
        }
        public static R<RP<UserInExamInfo>> GetQuesionNaireUserList(string examId, string officeCode)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetGetData(new { examId = examId, officeCode = officeCode }).SetBaseUri(KPIData.ServerURL).SetUrl($"/publish/answer_user");
                if (!http.Excute(out var data))
                {
                    return R<RP<UserInExamInfo>>.Fail("数据异常");
                }
                return data.AsModel<R<RP<UserInExamInfo>>>();
            }
            catch (Exception ex)
            {
                return R<RP<UserInExamInfo>>.Fail("数据异常");
            }
        }

        public static R<ExamRecordVO> GetNaireDetailByUserId(string examId, string userId)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetGetData(new { examId = examId, userId = userId }).SetBaseUri(KPIData.ServerURL).SetUrl($"/publish/exam_user");
                if (!http.Excute(out var data))
                {
                    return R<ExamRecordVO>.Fail("数据异常");
                }
                return data.AsModel<R<ExamRecordVO>>();
            }
            catch (Exception ex)
            {
                return R<ExamRecordVO>.Fail("数据异常");
            }
        }

        ///luna/assist/v1/publish/answer_user
    }
}
